package br.com.vti.sisp_sicrim.antigo.controller.relatorios;

import java.io.FileNotFoundException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import net.sf.jasperreports.engine.JRException;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.interceptor.download.InputStreamDownload;
import br.com.vti.sisp_sicrim.antigo.model.DidEmissao;
import br.com.vti.sisp_sicrim.antigo.model.SicEstatistica;
import br.com.vti.sisp_sicrim.antigo.model.Sislct01;
import br.com.vti.sisp_sicrim.antigo.model.Sisldat8;
import br.com.vti.sisp_sicrim.antigo.util.Relatorios;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;

/**
 * Classe responsavel por encapsular o tratamento e as consistencias da tela Scrpp004Report
 * 
 * @author Incode - Data: mai/2014
 * 
 */
public class Scrpp004Report {
	private String nomeClasse;
	private int dtini;
	private String jNomeide;
	private int jCont;
	private String dataCorrente;
	private int jUsuario;
	private int dtfim;
	private Long didemiRegger; // DB
	private Long didemiNserie; // DB
	private Integer didemiHoremi; // DB
	private Integer didemiMatfun; // DB
	public int datini;
	public int datfim;
	private String nroPagina;
	private String horaCorrente;
	private Result result;
	private Sessao sessao;
	private Relatorios report;
	// Classes views
	SicEstatistica vwCadest = new SicEstatistica();
	DidEmissao vwEmissao = new DidEmissao();
	// Classes includes
	Sislct01 sislct01 = new Sislct01();
	Sisldat8 sisldat8 = new Sisldat8();

	public Scrpp004Report() throws JRException, ParseException {
		inicializar();
	}

	public Scrpp004Report(Sessao sessao) throws JRException, ParseException {
		this.sessao = sessao;
		inicializar();
	}

	public void inicializar() throws JRException, ParseException {
		report = new Relatorios();
		nomeClasse = this.getClass().getSimpleName();
		dtini = 0;
		jNomeide = "";
		jCont = 0;
		jUsuario = 0;
		dtfim = 0;
		horaCorrente = new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()); // *TIMX
		dataCorrente = new SimpleDateFormat("dd/MM/yyyy").format(Calendar.getInstance().getTime()); // *DATE
		report.setNumeroRel(1, "C");
		{
			report.setNumeroLinhaRel(1, 1);
			{
				report.adicionaCampo(1, 2, "lit_1_2", "C", "", "  ");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(2, 3);
			{
				report.adicionaCampo(1, 62, "lit_1_62", "C", "", "* GEJUSPC - GERENCIA DA JUSTICA, SEGURANCA PUBLICA E CIDADANIA");
				report.adicionaCampo(110, 8, "lit_110_8", "C", "", "Pagina: ");
				report.adicionaCampo(119, 5, "nroPagina", "S", "Z.ZZ9", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(3, 3);
			{
				report.adicionaCampo(1, 67, "lit_1_67", "C", "", "* STI- SUBGERENCIA DE TECNOLOGIA DA INFORMCAO - SHOPPING DO CIDADAO");
				report.adicionaCampo(110, 8, "lit_110_8", "C", "", "Data..: ");
				report.adicionaCampo(119, 10, "dataCorrente", "S", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(4, 1);
			{
				report.adicionaCampo(1, 47, "lit_1_47", "C", "", "* INSTITUICAO DE IDENTIFICACAO CIVIL E CRIMINAL");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(5, 7);
			{
				report.adicionaCampo(1, 47, "lit_1_47", "C", "", "* RELATORIO DE ATESTADOS EMITIDOS NO PROCID    ");
				report.adicionaCampo(10, 9, "lit_10_9", "C", "", "PERIODO: ");
				report.adicionaCampo(20, 8, "Dtini", "N", "99/99/9999", "");
				report.adicionaCampo(29, 2, "lit_29_2", "C", "", " -");
				report.adicionaCampo(32, 8, "Dtfim", "N", "99/99/9999", "");
				report.adicionaCampo(5, 9, "lit_5_9", "C", "", "USUARIO: ");
				report.adicionaCampo(15, 7, "Jusuario", "N", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(6, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(7, 6);
			{
				report.adicionaCampo(1, 11, "lit_1_11", "C", "", "REG. GERAL.");
				report.adicionaCampo(16, 11, "lit_16_11", "C", "", "NUM. DOCUM.");
				report.adicionaCampo(30, 17, "lit_30_17", "C", "", "NOME DO INDIVIDUO");
				report.adicionaCampo(72, 10, "lit_72_10", "C", "", "DAT. EMISS");
				report.adicionaCampo(84, 8, "lit_84_8", "C", "", "HOR. EMI");
				report.adicionaCampo(94, 7, "lit_94_7", "C", "", "MAT.FUN");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(8, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
		}
		report.setNumeroRel(2, "D");
		{
			report.setNumeroLinhaRel(1, 6);
			{
				report.adicionaCampo(1, 13, "Didemiregger", "N", "ZZZZZZZZZZZZ-Z", "");
				report.adicionaCampo(16, 13, "Dideminserie", "N", "", "");
				report.adicionaCampo(30, 40, "Jnomeide", "X", "", "");
				report.adicionaCampo(72, 8, "Dtini", "N", "99/99/9999", "");
				report.adicionaCampo(84, 6, "Didemihoremi", "N", "99:99:99", "");
				report.adicionaCampo(94, 7, "Didemimatfun", "N", "9999999", "");
				report.setFimLinhaRel();
			}
		}
		report.setNumeroRel(3, "D");
		{
			report.setNumeroLinhaRel(1, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(2, 2);
			{
				report.adicionaCampo(1, 25, "lit_1_25", "C", "", "REGISTROS PROCESSADOS  = ");
				report.adicionaCampo(27, 4, "Jcont", "N", "", "");
				report.setFimLinhaRel();
			}
		}
		setDataCorrente(dataCorrente);
		setHoraCorrente(horaCorrente);
	}

	public boolean validar() {
		return true;
	}

	public String getNomeClasse() {
		return nomeClasse;
	}

	public void setNomeClasse(String nomeClasse) throws ParseException {
		this.nomeClasse = nomeClasse;
		report.adicionaValorReport("Program", nomeClasse);
	}

	public int getDtini() {
		return dtini;
	}

	public void setDtini(int dtini) throws ParseException {
		this.dtini = dtini;
		report.adicionaValorReport("Dtini", dtini);
	}

	public String getJnomeide() {
		return jNomeide;
	}

	public void setJnomeide(String jNomeide) throws ParseException {
		this.jNomeide = jNomeide;
		report.adicionaValorReport("Jnomeide", jNomeide);
	}

	public int getJcont() {
		return jCont;
	}

	public void setJcont(int jCont) throws ParseException {
		this.jCont = jCont;
		report.adicionaValorReport("Jcont", jCont);
	}

	public int getJusuario() {
		return jUsuario;
	}

	public void setJusuario(int jUsuario) throws ParseException {
		this.jUsuario = jUsuario;
		report.adicionaValorReport("Jusuario", jUsuario);
	}

	public int getDtfim() {
		return dtfim;
	}

	public void setDtfim(int dtfim) throws ParseException {
		this.dtfim = dtfim;
		report.adicionaValorReport("Dtfim", dtfim);
	}

	public String getNroPagina() {
		return nroPagina;
	}

	public void setNroPagina(String nroPagina) throws ParseException {
		this.nroPagina = nroPagina;
		report.adicionaValorReport("nroPagina", nroPagina);
	}

	public String getHoraCorrente() {
		return horaCorrente;
	}

	public void setHoraCorrente(String horaCorrente) throws ParseException {
		this.horaCorrente = horaCorrente;
		report.adicionaValorReport("horaCorrente", horaCorrente);
	}

	public String getDataCorrente() {
		return dataCorrente;
	}

	public void setDataCorrente(String dataCorrente) throws ParseException {
		this.dataCorrente = dataCorrente;
		report.adicionaValorReport("dataCorrente", dataCorrente);
	}

	public void setPageSize(int pagesize) throws JRException {
		report.setPageSize(pagesize);
	}

	public void setLineSize(int linesize) {
		report.setLineSize(linesize);
	}

	public int getPageSize() {
		return report.getPageSize();
	}

	public int getPageLine() {
		return report.getPageLine();
	}

	public void saltaLinhas(int qtdLinhas) throws ParseException, JRException {
		report.saltaLinhas(qtdLinhas);
	}

	public void gravaRelatorio(int nroRel) throws ParseException, JRException {
		setNroPagina(String.valueOf(report.getPageNumber()));
		report.gravaRelatorio(report, nroRel, false);
	}

	public InputStreamDownload imprimir() throws FileNotFoundException, JRException {
		return report.imprimir();
	}

	public Long getDidemiRegger() {
		return didemiRegger;
	}

	public void setDidemiRegger(Long didemiRegger) throws ParseException {
		this.didemiRegger = didemiRegger;
		report.adicionaValorReport("didemiRegger", didemiRegger);
	}

	public Long getDidemiNserie() {
		return didemiNserie;
	}

	public void setDidemiNserie(Long didemiNserie) throws ParseException {
		this.didemiNserie = didemiNserie;
		report.adicionaValorReport("didemiNserie", didemiNserie);
	}

	public Integer getDidemiHoremi() {
		return didemiHoremi;
	}

	public void setDidemiHoremi(Integer didemiHoremi) throws ParseException {
		this.didemiHoremi = didemiHoremi;
		report.adicionaValorReport("didemiHoremi", didemiHoremi);
	}

	public Integer getDidemiMatfun() {
		return didemiMatfun;
	}

	public void setDidemiMatfun(Integer didemiMatfun) throws ParseException {
		this.didemiMatfun = didemiMatfun;
		report.adicionaValorReport("didemiMatfun", didemiMatfun);
	}

}
